package com.settlement.system.converter;

import com.alibaba.excel.converters.AutoConverter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.settlement.system.common.enums.InUseOrNotEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * 账单大类
 * @author author
 */
public class InUseOrNotConvert extends AutoConverter {

    @Override
    public WriteCellData convertToExcelData(Object value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {

        if(value!=null && !StringUtils.isEmpty(value.toString())){
            return new WriteCellData(InUseOrNotEnum.getNameByNo(value.toString()));
        }
        return new WriteCellData("");
    }

    @Override
    public Object convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        Object value = null;
        CellDataTypeEnum type = cellData.getType();
        if(type.equals(CellDataTypeEnum.NUMBER)){
            value = cellData.getNumberValue();
        }else if(type.equals(CellDataTypeEnum.STRING)){
            value = cellData.getStringValue();
        }
        if(value!=null && !StringUtils.isEmpty(value.toString())){
            return InUseOrNotEnum.getNoByName(value.toString());
        }
        return null;
    }
}
